<!-- 车型管理 -->
<template>
  <div class="dashboard-container car-models customer-list-box">
    <!-- header  -->
    <div
      class="white"
    >
      <el-form label-width="120px">
        <el-row :gutter="60">
          <el-col :span="8">
            <el-form-item label="车型编号:">
              <el-input
                v-model="form.id"
                clearable
                placeholder="请输入车型编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应载重量:">
              <el-select
                v-model="form.allowableLoad"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in allowableLoadList"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col
            :span="7"
            style="padding-reight: 20px"
          >
            <el-form-item label="应载体积:">
              <el-select
                v-model="form.allowableVolume"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in allowableVolumeList"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                >
                </el-option>
              </el-select></el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="车型类型:">
              <el-input
                v-model="form.name"
                placeholder="请输入车型编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-button
              type="danger"
              @click="search"
            >搜索</el-button>
            <el-button @click="reset">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- table  -->
    <div class="white pad">
      <el-button
        type="danger"
        style="margin-bottom: 20px"
        @click="open"
      >新增车型</el-button>
      <el-table
        :data="list"
        style="width: 100%"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60"
        > </el-table-column>
        <el-table-column
          prop="id"
          label="车型编号"
          width="180"
        > </el-table-column>
        <el-table-column
          prop="name"
          label="车辆类型"
          width="130"
        >
        </el-table-column>
        <el-table-column
          prop="num"
          label="车型数量"
          width="100"
        >
          <template v-slot="{ row }">
            <span>{{ row.num ? row.num : '0' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="allowableLoad"
          label="应载重量 (吨)"
          width="150"
        >
        </el-table-column>
        <el-table-column
          prop="allowableVolume"
          label="应载体积 (立方米)"
          width="150"
        >
        </el-table-column>
        <el-table-column
          prop="measureLong"
          label="长 (米)"
          width="100"
        > </el-table-column>
        <el-table-column
          prop="measureHigh"
          label="宽 (米)"
          width="100"
        > </el-table-column>
        <el-table-column
          prop="measureWidth"
          label="高 (米)"
          width="100"
        > </el-table-column>
        <el-table-column
          label="操作"
          fixed="right"
          width="110"
        >
          <template v-slot="{row}">
            <el-link
              type="primary"
              :underline="false"
              @click="edit(row.id)"
            >编辑</el-link>
            <span class="margin">|</span>
            <el-link
              type="danger"
              :underline="false"
              @click="del(row.id)"
            >删除</el-link>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页  -->
      <el-row
        type="flex"
        justify="center"
      >
        <el-col :span="12">
          <el-pagination
            :current-page="form.page"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="form.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="counts"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          >
          </el-pagination>
        </el-col>
      </el-row>
      <!-- 添加弹窗 -->
      <CarModelsAdd
        ref="addForm"
        :dialog-form-visible.sync="dialogFormVisible"
        @update="listData"
      ></CarModelsAdd>
    </div>
  </div>

</template>
<script>
import CarModelsAdd from './components/car-models-add'
import { list, del } from '@/api/transit'
import { allowableLoadList, allowableVolumeList } from '@/api/car-models'
export default {
  components: {
    CarModelsAdd
  },
  data() {
    return {
      dialogFormVisible: false,
      allowableLoadList, // 应载重量下拉列表
      allowableVolumeList, // 应载体积下拉列表
      counts: 0,
      list: [],
      form: {
        page: 1, // 页码
        pageSize: 10, // 数量
        id: '', // 车型编号
        allowableLoad: '', // 应载重量
        allowableVolume: '', // 应载体积
        name: '' // 车型类型
      }
    }
  },
  created() {
    this.listData()
  },
  methods: {
    // 获取列表
    async listData() {
      const { data } = await list({
        page: this.form.page,
        pageSize: this.form.pageSize
      })
      console.log(data)
      this.list = data.items
      this.counts = +data.counts
      // console.log(this.counts)
    },
    // 改变条数
    handleSizeChange(val) {
      this.pageSize = val
      this.listData()
    },
    // 改变页数
    handleCurrentChange(val) {
      this.page = val
      this.listData()
    },
    // 搜索
    async search() {
      const { data } = await list(this.form)
      console.log(data)
      this.list = data.items
      this.counts = +data.counts
    },
    // 清空input框
    reset() {
      this.form = {
        page: 1, // 页码
        pageSize: 10, // 数量
        id: '', // 车型编号
        allowableLoad: '', // 应载重量
        allowableVolume: '', // 应载体积
        name: '' // 车型类型
      }
      this.listData()
    },
    // 点击新增按钮
    open() {
      this.dialogFormVisible = true
    },
    // 点击编辑按钮
    edit(id) {
      this.dialogFormVisible = true
      this.$refs.addForm.detail(id)
    },
    // 点击删除按钮
    del(id) {
      this.$confirm('确定要删除车型吗?', '删除确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await del(id)
        this.listData()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }

  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .el-form-item__label{
  font-weight: 400;
}
.margin{
  margin: 0 10px;
  color: #ccc;
}
.white {
  border-radius: 5px;
  margin: 10px;
  padding-top: 15px;
  background-color: #fff;
}
.pad {
  margin-bottom: 70px;
  padding: 20px;
}
.add-btn {
  margin-bottom: 20px;
}
.alert {
  margin: 10px 0px;
}
.pagination {
  margin-top: 40px;
  padding-bottom: 0px;
}

.el-select {
  width: 100%;
}

.car-models /deep/ .el-table td,
.el-table th {
  padding: 12px 0;
  min-width: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: left;
  overflow: hidden;
}
.car-models {
  /deep/ .el-dialog__title {
    width: 73px;
    height: 25px;
    font-size: 18px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: left;
    color: #20232a;
    line-height: 25px;
    letter-spacing: 0px;
  }
  /deep/ .el-dialog__body {
    text-align: center;
    padding: 40px 60px 0 30px;
  }
  .warn-img {
    width: 40px;
  }
  p {
    height: 24px;
    font-size: 16px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    color: #818693;
    line-height: 24px;
  }
}
</style>

